<#include "/include/head.html">
<html>
    <title></title>
<body>
    <form action="/user/addPhoto" id="photoForm" method="post">
        <input type="text" name="imgDescribe" id="imgDescribe" placeholder="请输入图片描述">
        <input type="hidden" name="imgUrl" id="imgUrl">
        <button type="button" onclick="toSub()">点击上传</button>${msg!}
    </form>
    <form id="formSave" action=""  method="POST" enctype="multipart/form-data">
        <input type="file"  name="file"  onchange="upload()" accept="image/gif,image/jpeg,image/jpg,image/png,image/svg">
    </form>
</body>
<script>

    function upload() {
        var formData = new FormData($( "#formSave" )[0]);
        $.ajax({
            url: '/user/qiNiuUpload',
            type: 'POST',
            data: formData,
            async: false,
            cache: false,
            dataType: "json",
            contentType: false,
            processData: false,
            success: function (data) {
                $("#imgUrl").val(data.path);
            },
            error: function (res) {
                showMessage(res);
            }
        });
    }

    function toSub() {

        if(ifBlank($("#imgDescribe").val(),"图片描述不能为空")){
            return;
        }
        if(ifBlank($("#imgUrl").val(),"图片地址不能为空")){
            return;
        }

        $("#photoForm").submit();
    }
</script>
</html>